package main;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import model.Tweet;
import model.User;
import model.UserGen;

import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.message.BasicNameValuePair;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

import ulity.ParserXml;

public class AutoUser extends Thread{
	public User user;
	private Connection conn;
	public String username;
	public String password;
	List<Tweet> timeline;
	private String maxUserId;
	List<User> sugguest;
	List<User> followings;
    private long lasttime;
    private int speed = 20;
    public boolean stop= false;
	public AutoUser(String user, String pass) {
		try {
			conn = new Connection();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		username = user;
		password = pass;
		this.user = new User("", "");
		timeline = new ArrayList<Tweet>();
		maxUserId = new String("-1");
		sugguest = new ArrayList<User>();
		followings = new ArrayList<User>();
		lasttime = 0;
		//login();
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public void register() {
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
		String uri = "Users/add";
		nameValuePairs.add(new BasicNameValuePair("username", this.username));
		nameValuePairs.add(new BasicNameValuePair("password", this.password));
		
		FutureCallback<HttpResponse> callback = new FutureCallback<HttpResponse>() {

			public void completed(final HttpResponse response) {
				String myString;
				try {
					myString = IOUtils.toString(response.getEntity()
							.getContent(), "UTF-8");
					System.out.println(myString);
				} catch (IllegalStateException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				System.out.println("register->" + response.getStatusLine());
			}

			public void failed(final Exception ex) {

				System.out.println("register->" + ex);
			}

			public void cancelled() {

				System.out.println("register cancelled");
			}

		};
		try {
			conn.post(uri, nameValuePairs, callback);
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	public void login() {
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
		String uri = "Users/login";
		nameValuePairs.add(new BasicNameValuePair("username", this.username));
		nameValuePairs.add(new BasicNameValuePair("password", this.password));
		FutureCallback<HttpResponse> callback = new FutureCallback<HttpResponse>() {

			public void completed(final HttpResponse response) {
				String myString;
				try {
					myString = IOUtils.toString(response.getEntity()
							.getContent(), "UTF-8");

					JSONParser parser = new JSONParser();

					JSONObject json = (JSONObject) parser.parse(myString);
					String status_code = json.get("status_code").toString();
					if (status_code.equals("0")) {
						System.out.println(json.toString());
						// JSONArray jsonarr = (JSONArray)json.get("entity");
						json = (JSONObject) json.get("entity");
						json = (JSONObject) json.get("User");
						// System.out.println((String)json.get("id"));
						user.setUserID(json.get("id").toString());
						user.setUserName(json.get("username").toString());
						user.setAccesstoken(json.get("accesstoken").toString());
						user.setUserEmail((String) json.get("email"));
						user.setUserScreenName(json.get("screen_name")
								.toString());
						// System.out.println(json.toString());
						// user.setUserID((String)json.get("id"));
						/*
						 * System.out.println(jsonarr.toString()); json =
						 * (JSONObject)json.get("User"); for (Object object :
						 * jsonarr) { JSONObject jsonobj = (JSONObject)object;
						 * 
						 * user.setUserID(jsonobj.get("id").toString());
						 * user.setUserName(jsonobj.get("username").toString());
						 * user
						 * .setAccesstoken(jsonobj.get("accesstoken").toString
						 * ());
						 * user.setUserEmail(jsonobj.get("email").toString());
						 * user
						 * .setUserScreenName(jsonobj.get("screen_name").toString
						 * ()); }
						 */

					} else {

					}

				} catch (IllegalStateException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				System.out.println("login->" + response.getStatusLine());
			}

			public void failed(final Exception ex) {

				System.out.println("login->" + ex);
			}

			public void cancelled() {

				System.out.println("login cancelled");
			}

		};
		try {
			conn.post(uri, nameValuePairs, callback);
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	public void tweet() {
		// String api= "Tweets/update";
		/*
		 * RequestParams params = new RequestParams(); params.put("content",
		 * t.getContent()); params.put("image_url", t.getImgURL());
		 * params.put("parent_id", t.getParentTweetId()); params.put("type",
		 * t.getType());
		 */
		if(this.user.getUserID()==null)return;
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
		String uri = "Tweets/update";
		System.out.println(this.user.getUserID());
		nameValuePairs.add(new BasicNameValuePair("user_id", this.user
				.getUserID()));
		nameValuePairs.add(new BasicNameValuePair("content", this.user
				.getUserName() + System.currentTimeMillis()));
		nameValuePairs.add(new BasicNameValuePair("image_url", ""));
		nameValuePairs.add(new BasicNameValuePair("parent_id", "-1"));
		nameValuePairs.add(new BasicNameValuePair("place_id", "1"));
		nameValuePairs.add(new BasicNameValuePair("type", "1"));
		
		FutureCallback<HttpResponse> callback = new FutureCallback<HttpResponse>() {

			public void completed(final HttpResponse response) {
				String myString;
				try {
					myString = IOUtils.toString(response.getEntity()
							.getContent(), "UTF-8");
					System.out.println(myString);
					JSONParser parser = new JSONParser();

					JSONObject json = (JSONObject) parser.parse(myString);
					String status_code = json.get("status_code").toString();
					if (status_code.equals("0")) {
						// System.out.println(json.toString());

					} else {

					}
				} catch (IllegalStateException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				System.out.println("tweet" + response.getStatusLine());
			}

			public void failed(final Exception ex) {

				System.out.println("tweet->" + ex);
			}

			public void cancelled() {

				System.out.println("tweet cancelled");
			}

		};
		try {
			conn.post(uri, nameValuePairs, callback);
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void getTimeLine() {
		if(this.user.getUserID()==null)return ;
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
		String uri = "Timelines/home_timeline";
		
		System.out.println(this.user.getUserID());
		nameValuePairs.add(new BasicNameValuePair("user_id", this.user
				.getUserID()));
		nameValuePairs.add(new BasicNameValuePair("max_tweet_id",
				this.maxUserId));
		nameValuePairs.add(new BasicNameValuePair("count", "20"));

		FutureCallback<HttpResponse> callback = new FutureCallback<HttpResponse>() {

			public void completed(final HttpResponse response) {
				String myString;
				try {
					myString = IOUtils.toString(response.getEntity()
							.getContent(), "UTF-8");
					System.out.println(myString);
					JSONParser parser = new JSONParser();

					JSONObject json = (JSONObject) parser.parse(myString);
					String status_code = json.get("status_code").toString();
					if (status_code.equals("0")) {
						// System.out.println(json.toString());
						JSONArray jsonarr = (JSONArray) json.get("entity");

						// json = (JSONObject)json.get("entity");
						// json = (JSONObject)json.get("User");
						// System.out.println((String)json.get("id"));
						// user.setUserID(json.get("id").toString());
						// user.setUserName(json.get("username").toString());
						// user.setAccesstoken(json.get("accesstoken").toString());
						// user.setUserEmail((String)json.get("email"));
						// user.setUserScreenName(json.get("screen_name").toString());
						// System.out.println(json.toString());
						// user.setUserID((String)json.get("id"));
						// System.out.println(jsonarr.toString());
						// json = (JSONObject)json.get("User");
						for (Object object : jsonarr) {
							JSONObject jsonobj = (JSONObject) object;
							//System.out.println(jsonobj.toString());
							JSONObject userjs = (JSONObject) jsonobj
									.get("User");
							JSONObject tweetjs = (JSONObject) jsonobj
									.get("Tweet");
							User u = paserUser(userjs);
							Tweet tweet = paserTweet(tweetjs);
							tweet.setUser(u);
							if(tweet.getType().equals("3")){
							  JSONObject retweet =(JSONObject) jsonobj.get("ReTweet");
							  JSONObject rtuser = (JSONObject)jsonobj.get("RTUser");
							  
							  Tweet parentTweet = paserTweet(retweet);
							  User paru = paserUser(rtuser);
							  parentTweet.setUser(paru);
							  tweet.setRetweet(parentTweet);
							}
							timeline.add(tweet);

						}
						if (timeline.size() > 0) {
							maxUserId = timeline.get(timeline.size() - 1)
									.getTweetId();
						}
						if (jsonarr.size() == 0) {
							maxUserId = "-1";
							timeline.clear();
						}

					} else {

					}
				} catch (IllegalStateException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				System.out.println("getTimeLine->" + response.getStatusLine());
			}

			public void failed(final Exception ex) {

				System.out.println("getTimeLine->" + ex);
			}

			public void cancelled() {

				System.out.println("getTimeLine cancelled");
			}

		};
		try {
			conn.post(uri, nameValuePairs, callback);
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static User paserUser(JSONObject obj) {
		User result = new User("", "");
		result.setUserName((String) obj.get("username"));
		/*
		 * if (obj.getString("accesstoken") != null)
		 * result.setAccesstoken(obj.getString("accesstoken"));
		 */
		result.setUserID((String) obj.get("id"));
		result.setCreatedDate((String) obj.get("created"));
		result.setUserAvatarURL((String) obj.get("avatar"));
		// Log.i("test","avata url"+result.getUserAvatarURL());
		// Log.d("test","obj:"obj.)
		result.setUserScreenName((String) obj.get("screen_name"));
		return result;
	}

	public static Tweet paserTweet(JSONObject tempTweetJS) {
		Tweet tempTweet = new Tweet();

		tempTweet.setType((String) tempTweetJS.get("type"));

		/*
		 * if ((tempTweet.getType()).equals("3")) {// is retweet JSONObject
		 * retweet = tempTweetJS.getJSONObject("Tweet")
		 * .getJSONObject("retweet"); if (retweet != null) { Tweet tempRetweet =
		 * new Tweet(); tempRetweet = paserTweet(retweet);
		 * tempTweet.setRetweet(tempRetweet); } }
		 */

		tempTweet.setImgURL((String) tempTweetJS.get("image_url"));
		tempTweet.setParentTweetId((String) tempTweetJS.get("parent_id"));
		tempTweet.setTweetId((String) tempTweetJS.get("id"));
		tempTweet.setContent((String) tempTweetJS.get("content"));

		if ((String) tempTweetJS.get("favorite") != null)
			tempTweet.setFavorite((String) tempTweetJS.get("favorite"));
		tempTweet.setCreatedDate((String) tempTweetJS.get("created"));

		return tempTweet;
	}

	public void retweet() {
		if(this.user.getUserID()==null)return ;
		System.out.println("retweet");
		int size = timeline.size();
		int index;
		if (size > 0) {
			index = (int) (size * Math.random());
			Tweet tweet = timeline.get(index);
			
			if (tweet.getUser().getUserID().equals(this.user.getUserID())) {
				System.out.println("retwee1t");
			} else {
				if(tweet.getType().equals("3")){
					tweet=tweet.getRetweet();
				}
				System.out.println("retwe2et");
				List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
				String uri = "Tweets/retweet";
				nameValuePairs.add(new BasicNameValuePair("tweet_id", tweet
						.getTweetId()));
				nameValuePairs.add(new BasicNameValuePair("user_id", this.user
						.getUserID()));
				FutureCallback<HttpResponse> callback = new FutureCallback<HttpResponse>() {

					public void completed(final HttpResponse response) {
						String myString;
						try {
							myString = IOUtils.toString(response.getEntity()
									.getContent(), "UTF-8");
							System.out.println(myString);
						} catch (IllegalStateException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} catch (IOException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}

						System.out.println("getTimeLine->" + response.getStatusLine());
					}

					public void failed(final Exception ex) {

						System.out.println("getTimeLine->" + ex);
					}

					public void cancelled() {

						System.out.println("getTimeLine cancelled");
					}

				};
				try {
					conn.post(uri, nameValuePairs, callback);
				} catch (UnsupportedEncodingException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

			}
		}
	}

	public void delete() {
		if(this.user.getUserID()==null)return ;
		System.out.println("delete");
		int size = timeline.size();
		int index;
		System.out.println(size);
		if (size > 0) {
			index = (int) (size * Math.random());
			Tweet tweet = null;
			System.out.println(index);
			for (int i = index; i < size; i++) {
				Tweet tweet1 = timeline.get(i);
				if (tweet1.getUser().getUserID().equals(this.user.getUserID())) {
					tweet = tweet1;
					timeline.remove(i);
					break;
				}

			}
			if (tweet == null) {
				System.out.println("delte");
				return;
			}
			System.out.println("delte2");
			List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
			String uri = "Tweets/delete";
			nameValuePairs.add(new BasicNameValuePair("tweet_id", tweet
					.getTweetId()));
			nameValuePairs.add(new BasicNameValuePair("user_id", this.user
					.getUserID()));
			FutureCallback<HttpResponse> callback = new FutureCallback<HttpResponse>() {

				public void completed(final HttpResponse response) {
					String myString;
					try {
						myString = IOUtils.toString(response.getEntity()
								.getContent(), "UTF-8");
						System.out.println(myString);
					} catch (IllegalStateException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}

					System.out.println("delete->" + response.getStatusLine());
				}

				public void failed(final Exception ex) {

					System.out.println("delete->" + ex);
				}

				public void cancelled() {

					System.out.println("delete cancelled");
				}

			};
			try {
				conn.post(uri, nameValuePairs, callback);
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}

	}

	public void followAUser(User user) {
		if(this.user.getUserID()==null)return ;
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
		String uri = "Follows/follow";
		System.out.println(this.user.getUserID());
		nameValuePairs.add(new BasicNameValuePair("userid", this.user
				.getUserID()));

		nameValuePairs.add(new BasicNameValuePair("followedId", user
				.getUserID()));
		FutureCallback<HttpResponse> callback = new FutureCallback<HttpResponse>() {

			public void completed(final HttpResponse response) {
				String myString;
				try {
					myString = IOUtils.toString(response.getEntity()
							.getContent(), "UTF-8");
					System.out.println(myString);
					JSONParser parser = new JSONParser();

					JSONObject json = (JSONObject) parser.parse(myString);
					String status_code = json.get("status_code").toString();
					if (status_code.equals("0")) {
						System.out.println(json.toString());

					} else {

					}
				} catch (IllegalStateException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				System.out.println("followAUser->" + response.getStatusLine());
			}

			public void failed(final Exception ex) {

				System.out.println("followAUser->" + ex);
			}

			public void cancelled() {

				System.out.println("followAUser cancelled");
			}

		};
		try {
			conn.post(uri, nameValuePairs, callback);
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void follow() {
		if(this.user.getUserID()==null)return ;
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
		String uri = "Users/suggest";
		System.out.println(this.user.getUserID());
		nameValuePairs.add(new BasicNameValuePair("user_id", this.user
				.getUserID()));

		FutureCallback<HttpResponse> callback = new FutureCallback<HttpResponse>() {

			public void completed(final HttpResponse response) {
				String myString;
				try {
					myString = IOUtils.toString(response.getEntity()
							.getContent(), "UTF-8");
					System.out.println(myString);
					JSONParser parser = new JSONParser();

					JSONObject json = (JSONObject) parser.parse(myString);
					String status_code = json.get("status_code").toString();
					if (status_code.equals("0")) {
						// System.out.println(json.toString());
						JSONArray jsonarr = (JSONArray) json.get("entity");

						// json = (JSONObject)json.get("entity");
						// json = (JSONObject)json.get("User");
						// System.out.println((String)json.get("id"));
						// user.setUserID(json.get("id").toString());
						// user.setUserName(json.get("username").toString());
						// user.setAccesstoken(json.get("accesstoken").toString());
						// user.setUserEmail((String)json.get("email"));
						// user.setUserScreenName(json.get("screen_name").toString());
						// System.out.println(json.toString());
						// user.setUserID((String)json.get("id"));
						// System.out.println(jsonarr.toString());
						// json = (JSONObject)json.get("User");
						for (Object object : jsonarr) {
							JSONObject jsonobj = (JSONObject) object;
							System.out.println(jsonobj.toString());
							JSONObject userjs = (JSONObject) jsonobj
									.get("User");

							User u = paserUser(userjs);
							followAUser(u);

							// sugguest.add(u);

						}

					} else {

					}
				} catch (IllegalStateException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				System.out.println("follow->" + response.getStatusLine());
			}

			public void failed(final Exception ex) {

				System.out.println("follow->" + ex);
			}

			public void cancelled() {

				System.out.println("follow cancelled");
			}

		};
		try {
			conn.post(uri, nameValuePairs, callback);
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void unfollowAUser(User user) {
		if(this.user.getUserID()==null)return ;
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
		String uri = "Follows/unfollow";
		System.out.println(this.user.getUserID());
		nameValuePairs.add(new BasicNameValuePair("userid", this.user
				.getUserID()));

		nameValuePairs.add(new BasicNameValuePair("followedId", user
				.getUserID()));
		FutureCallback<HttpResponse> callback = new FutureCallback<HttpResponse>() {

			public void completed(final HttpResponse response) {
				String myString;
				try {
					myString = IOUtils.toString(response.getEntity()
							.getContent(), "UTF-8");
					System.out.println(myString);
					JSONParser parser = new JSONParser();

					JSONObject json = (JSONObject) parser.parse(myString);
					String status_code = json.get("status_code").toString();
					if (status_code.equals("0")) {
						System.out.println(json.toString());

					} else {

					}
				} catch (IllegalStateException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				System.out.println("unfollowAUser->" + response.getStatusLine());
			}

			public void failed(final Exception ex) {

				System.out.println("unfollowAUser->" + ex);
			}

			public void cancelled() {

				System.out.println("unfollowAUser cancelled");
			}

		};
		try {
			conn.post(uri, nameValuePairs, callback);
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void unfollow() {
		if(this.user.getUserID()==null)return ;
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
		String uri = "Follows/followings";
		System.out.println(this.user.getUserID());
		nameValuePairs.add(new BasicNameValuePair("get_userid", this.user
				.getUserID()));
		nameValuePairs.add(new BasicNameValuePair("userid", this.user
				.getUserID()));

		FutureCallback<HttpResponse> callback = new FutureCallback<HttpResponse>() {

			public void completed(final HttpResponse response) {
				String myString;
				try {
					myString = IOUtils.toString(response.getEntity()
							.getContent(), "UTF-8");
					System.out.println(myString);
					JSONParser parser = new JSONParser();

					JSONObject json = (JSONObject) parser.parse(myString);
					String status_code = json.get("status_code").toString();
					if (status_code.equals("0")) {
						// System.out.println(json.toString());
						JSONArray jsonarr = (JSONArray) json.get("entity");

						// json = (JSONObject)json.get("entity");
						// json = (JSONObject)json.get("User");
						// System.out.println((String)json.get("id"));
						// user.setUserID(json.get("id").toString());
						// user.setUserName(json.get("username").toString());
						// user.setAccesstoken(json.get("accesstoken").toString());
						// user.setUserEmail((String)json.get("email"));
						// user.setUserScreenName(json.get("screen_name").toString());
						// System.out.println(json.toString());
						// user.setUserID((String)json.get("id"));
						// System.out.println(jsonarr.toString());
						// json = (JSONObject)json.get("User");
						for (Object object : jsonarr) {
							JSONObject jsonobj = (JSONObject) object;
							System.out.println(jsonobj.toString());
							JSONObject userjs = (JSONObject) jsonobj
									.get("FollowerUser");

							User u = paserUser(userjs);

							followings.add(u);

						}
						int size = followings.size();
						if (size > 0) {
							int index = (int) (size * Math.random());
							User user = followings.get(index);
							unfollowAUser(user);
							followings.clear();
						}
					} else {

					}
				} catch (IllegalStateException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				System.out.println("->" + response.getStatusLine());
			}

			public void failed(final Exception ex) {

				System.out.println("->" + ex);
			}

			public void cancelled() {

				System.out.println(" cancelled");
			}

		};
		try {
			conn.post(uri, nameValuePairs, callback);
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
    public void procedure(){
    	long curTime =System.currentTimeMillis()/(100*speed);
    	if(curTime!=lasttime){
    		if(curTime%2==0){
    		    this.getTimeLine();
    			this.retweet();
    			this.follow();
    			//tweet
    			this.tweet();
    		}
//    		if(curTime%5==0){
//    			//timeline
//    			this.getTimeLine();
//    		}
//    		if(curTime%7==0){
//    			//retweet
//    			this.retweet();
//    		}
//    		if(curTime%11==0){
//    			//delete
//    			this.delete();
//    		}
//    		if(curTime%13==0){
//    			//follow
//    			this.follow();
//    		}
//    		if(curTime%17==0){
//    			//unfollow
//    			this.unfollow();
//    		}
    		lasttime = curTime;
    	}
    	
    	
    	
    	
    	
    	
    	//lasttime = curTime;
    }
    
	
	@SuppressWarnings("static-access")
	public void run() {
		// TODO Auto-generated method stub
		while(!stop){
			procedure();
			try {
				Thread.currentThread().sleep(800);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	public static void main(String[] args) throws InterruptedException {
		User user = new User("", "");
//
		AutoUser auto = new AutoUser("c", "1");
		//auto.login();
	    //auto.register();
	    //Thread.sleep(2000);
	    auto.login();
	    Thread.sleep(2000);
	    auto.getTimeLine();
		//auto.start();
//		AutoUser auto1 = new AutoUser("b", "b");
//		// auto.register();
//		auto1.login();
//		auto1.start();
//		List<UserGen>  users = ParserXml.readUser("data/user2.xml");
//		List<AutoUser> autos = new ArrayList<AutoUser>();
//		for(int i = 0;i<users.size()-500;i++){
//			autos.add(new AutoUser(users.get(i).getUserName(), users.get(i).getPass()));
//		}
//		for(int i =0; i<autos.size();i++){
//			Thread.sleep(10);
//			autos.get(i).login();
//		}
//		for(int i =0; i<autos.size();i++){
//			Thread.sleep(10);
//			autos.get(i).start();
//		}
	}
}
